package com.qf.serviceimpl;

import com.qf.dao.AccountDao;
import com.qf.entity.Account;
import com.qf.service.AccountService;

/**
 * 事务转账
 */
@SuppressWarnings("all")
public class AccountServiceImpl implements AccountService {

    AccountDao accountDao ;

    public void setDao(AccountDao dao) {
        this.accountDao = dao;
    }

    @Override
    public void transfer(String fromName, String toName, double money) {

//        根据名字查询余额
        Account account = accountDao.selectByName(fromName);
        Account account1 = accountDao.selectByName(toName);

//        进行转账，修改
        account.setMoney(account.getMoney()-money);
        account1.setMoney(account1.getMoney()+money);

//        更新数据库
        accountDao.update(account);
//        System.out.println(1/0);
        accountDao.update(account1);
    }
}
